From e6ff15b27ed3723cf50e2f896fc6fb2f6495e041 Mon Sep 17 00:00:00 2001 From: "kaf24@freefall.cl.cam.ac.uk" Date: Mon, 20 Sep 2004 09:57:48 +0000 Subject: [PATCH] bitkeeper revision 1.1159.79.4 (414ea99cE4RZfWihQhMkvClcGfAGEA) Daemonization fixes for xend. For some reason I cannot capture output from C extensions that use printf/fprintf to stdout and stderr. This can't be hard to fix though. --- tools/python/xen/xend/server/SrvDaemon.py | 28 +++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tools/python/xen/xend/server/SrvDaemon.py b/tools/python/xen/xend/server/SrvDaemon.py index bdd4db83c0..771472a311 100644 --- a/tools/python/xen/xend/server/SrvDaemon.py +++ b/tools/python/xen/xend/server/SrvDaemon.py @@ -42,7 +42,7 @@ import console import domain from params import * -DEBUG = 0 +DEBUG = 1 class NotifierProtocol(protocol.Protocol): """Asynchronous handler for i/o on the notifier (event channel). @@ -475,14 +475,24 @@ class Daemon: xfrd_pid = self.cleanup_xfrd() # Detach from TTY. - if not DEBUG: - os.setsid() - sys.stdin.close(); - sys.stdout.close(); - sys.stderr.close(); - os.close(0); - os.close(1); - os.close(2); + os.setsid() + + # Detach from standard file descriptors. + # I do this at the file-descriptor level: the overlying Python file + # objects also use fd's 0, 1 and 2. + os.close(0) + os.close(1) + os.close(2) + if DEBUG: + os.open('/dev/null', os.O_RDONLY) + # XXX KAF: Why doesn't this capture output from C extensions that + # fprintf(stdout) or fprintf(stderr) ?? + os.open('/var/log/xend-debug.log', os.O_WRONLY|os.O_CREAT) + else: + os.open('/dev/null', os.O_RDWR) + os.dup(0) + os.dup(1) + if self.set_user(): return 4 os.chdir("/") -- 2.30.2